package com.mvc.frame.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//HandlerInterceptorAdapter
//跨域设置
public class CrossInterceptor extends HandlerInterceptorAdapter 
{
	@Value("${allow.origin}")
	private String allowOrigin;

   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception 
   {
        response.addHeader("Access-Control-Allow-Origin",allowOrigin);
        response.addHeader("Access-Control-Allow-Methods","*");
        response.addHeader("Access-Control-Max-Age","100");
        response.addHeader("Access-Control-Allow-Headers", "Content-Type");
        //允许客户端发送cookies true表示接收，false不接受 默认为false？
        response.addHeader("Access-Control-Allow-Credentials","true");
        return super.preHandle(request, response, handler);
    } 

}
